Skip to content

Small fix: arithmetic_analysis/newton_method.py #2498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2020

Conversation

dhruvmanila
Copy link
Member

Small fix to arithmetic_analysis/newton_method.py

When you raise inside an except block you will get two traceback.

>>> try:
...     a = 1/0
... except ZeroDivisionError:
...     raise ZeroDivisionError("Not possible")
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ZeroDivisionError: division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
ZeroDivisionError: Not possible

Why? the except block is used to handle the exceptions, if you want to raise an exception inside it you need to use the from clause like so:

>>> try:
...     a = 1/0
... except ZeroDivisionError:
...     raise ZeroDivisionError("Not possible") from None
...
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
ZeroDivisionError: Not possible

Describe your change:

  • Fix a bug or typo in an existing algorithm?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@cclauss cclauss closed this Sep 27, 2020
@cclauss cclauss reopened this Sep 27, 2020
@cclauss cclauss closed this Sep 27, 2020
@cclauss cclauss reopened this Sep 27, 2020
@cclauss cclauss merged commit 187e8cc into TheAlgorithms:master Sep 27, 2020
@TravisBuddy
Copy link

Hey @dhruvmanila,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: 36d387a0-00c2-11eb-a257-6fde496095bb

@dhruvmanila dhruvmanila deleted the patch-error branch September 28, 2020 04:48
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants